//
//  GoodsDetailsViewController.m
//  NoNeedle
//
//  Created by chirui on 17/3/3.
//  Copyright © 2017年 Ming Tian. All rights reserved.
//

#import "GoodsDetailsViewController.h"
//#import "SHSureOrderViewController.h" // 确认订单
#import "SHGoodsCommentListController.h"
#import "LinkSellerViewController.h" // 联系卖家

#import "SeeServiceViewController.h" //售后

@interface GoodsDetailsViewController ()<UIWebViewDelegate,UITableViewDataSource,UITableViewDelegate,SDCycleScrollViewDelegate>
{
    UITableView * _tableView;
    UIWebView * _webView;
    NSArray * commentArray;
    NSMutableArray * _cellHeightArray;
    NSString * _typeStr;
    int num; //购买数量
    int allNumber; // 总库存
    UILabel * price;
    UILabel * chooseNum;
    UILabel * numberLabel;

    NSInteger height;
    NSDictionary * dataDic;
    
    
    UIView * bgView;
    
}
@property (nonatomic,strong) SZTextView * introTextView;  //评论

@end

@implementation GoodsDetailsViewController

//-(void)viewDidLayoutSubviews {
//    
//    
//    self.view.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
//    
//    
//}

-(void)viewWillAppear:(BOOL)animated {

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.tabBarController.tabBar.hidden= YES;
    });
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _cellHeightArray = @[].mutableCopy;
    num =1;
    _typeStr = @"1";
    
    self.view.backgroundColor =[UIColor redColor];
    self.navigationItem.titleView=[TopLabel withLabelWithLabelText:@"商品详情"];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem rightItemWithIcon:@"sh_shopCar_icon" target:self action:@selector(shopCar)];
    
       
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,WIDTH,50)];
    _webView.scalesPageToFit = YES;
    _webView.delegate = self;
    _webView.scrollView.bounces=NO;
    _webView.scrollView.showsHorizontalScrollIndicator = NO;
    _webView.scrollView.scrollEnabled = NO;
    
    
    [self creatTableView];
    
    
    [self creatWEB];
    
    [self creatDownView];
    
    [self getGoodsDataRequest];
    [self getGoodsCommentDataRequest];
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"icon_public_return" target:self action:@selector(back)];
    
}


-(void)commentBtnClick{
    
    UIWindow *window = [[UIApplication sharedApplication].delegate window];
    
    bgView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    bgView.backgroundColor = ColorA(0, 0, 0, 0.5);
    
    
    UIView * view =[[UIView alloc]initWithFrame:CGRectMake(20, HEIGHT/2 -100, WIDTH - 40, 200)];
    view.backgroundColor =[UIColor whiteColor];
    view.layer.cornerRadius = 7.f;
    view.layer.masksToBounds = YES;
    
    
    UILabel * commentLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 10, WIDTH-40, 20)];
    commentLabel.textColor = [UIColor redColor];
    commentLabel.textAlignment = NSTextAlignmentCenter;
    commentLabel.text = @"评价";
    [view addSubview:commentLabel];
    
    UIButton * deledatebtn =[UIButton buttonWithType:UIButtonTypeCustom];
    deledatebtn.frame = CGRectMake(WIDTH - 70, 5, 25, 25);
    [deledatebtn setBackgroundImage:ImageName(@"btn_comment_close") forState:UIControlStateNormal];
    [deledatebtn addTarget:self action:@selector(deledateBtn) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:deledatebtn];
    
    self.introTextView = [[SZTextView alloc]init];
    self.introTextView.frame = CGRectMake(10, 40, WIDTH -60, 90);
    self.introTextView.font = [UIFont systemFontOfSize:15];
    self.introTextView.backgroundColor =[UIColor groupTableViewBackgroundColor];
    self.introTextView.placeholder = @"请输入内容...";
    [view addSubview:self.introTextView];
    
    
    UIButton * btn =[UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(40, 150, WIDTH -120, 40);
    btn.backgroundColor = NavBackColor;
    btn.layer.cornerRadius = 20.f;
    btn.layer.masksToBounds = YES;
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitle:@"确定" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(sureBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    
    [bgView addSubview:view];
    [window addSubview:bgView];
}

-(void)deledateBtn {
    
    [bgView removeFromSuperview];
    
}

-(void)sureBtnClick{


    if (self.introTextView.text.length<=0||self.introTextView.text==nil) {
        
        SHuiMBhudTextTimeStr(@"评价内容不能为空");
        return;
    }
    
    [bgView removeFromSuperview];
    
    [self addReplyCommentRequest];

}

-(void)back{
    
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)shopCar {

//    ShoppingCartViewController * shopCar =[[ShoppingCartViewController alloc]init];
//    shopCar.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:shopCar animated:YES];

}


-(void)creatTableView {
    
    _tableView  =[[UITableView alloc]initWithFrame:CGRectMake(0,0, WIDTH, HEIGHT-48)
                                             style:UITableViewStyleGrouped];
    _tableView.dataSource=self;
    _tableView.delegate =self;
    UIView * view =[[UIView alloc]init];
    _tableView.tableFooterView =view;
    [self.view addSubview:_tableView];
//    
//    MJRefreshNormalHeader * header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        
//        [self getGoodsDataRequest];
//        
//    }];
//    _tableView.mj_header = header;
}

-(void)creatWEB {
    
    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:dataDic[@"detail"]]]];
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    
    height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] integerValue];
    webView.frame = CGRectMake(0, 0, WIDTH,height);
    
    [_tableView reloadData];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if ([_typeStr isEqualToString:@"1"]) {
        return 1;
    }else {
        
        if (commentArray.count>10) {
        
            return 10;
        }else {
            return commentArray.count;
        }
    }
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([_typeStr isEqualToString:@"1"]) {
        static NSString * cellId =@"cellid";
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (cell==nil) {
            
            cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        }else {
        
            while ([cell.contentView.subviews lastObject]) {
                
                [[cell.contentView.subviews lastObject] removeFromSuperview];
            }
        }
        
        [cell.contentView addSubview:_webView];
        
        return cell;
    }else {
        
        static NSString * cellId =@"cellid";
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (cell==nil) {
            
            cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        }else{
            while ([cell.contentView.subviews lastObject]) {
                
                [[cell.contentView.subviews lastObject] removeFromSuperview];
            }
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        if (indexPath.row>10) {
            
            return cell;
            
        }else {
            
            
            if (commentArray.count>0) {
            
                
                NSDictionary * dic = commentArray[indexPath.row];
                UIView *view = [[UIView alloc]initWithFrame:CGRectMake(10, 5, WIDTH - 20, 2)];
                view.clipsToBounds = YES;
                view.layer.cornerRadius = 5.f;
                [cell.contentView addSubview:view];
                
                UIImageView * userImage =[[UIImageView alloc]initWithFrame:CGRectMake(0, 7, 50, 50)];
                userImage.layer.cornerRadius = 25.f;
                userImage.layer.masksToBounds = YES;
                [userImage sd_setImageWithURL:[NSURL URLWithString:dic[@"avatar"]] placeholderImage:[UIImage imageNamed:@"img_user_default"]];
                [view addSubview:userImage];
                
            
                UILabel * name =[[UILabel alloc]initWithFrame:CGRectMake(55, 9, 60, 20)];
                name.font =[UIFont systemFontOfSize:15];
                name.textColor =RGB(0x3c7420
                                    );
                name.text =dic[@"user_name"];
                [name sizeToFit];
                [view addSubview:name];
                
                UILabel * date =[[UILabel alloc]initWithFrame:CGRectMake(55, 39,WIDTH-70, 15)];
                date.font =[UIFont systemFontOfSize:13];
                date.textColor = [UIColor lightGrayColor];
                date.text = dic[@"comment_time"];
                [view addSubview:date];
                
            
                UILabel *contentLabel;
                
                contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(10,CGRectGetMaxY(date.frame)+10 , CGRectGetWidth(view.frame)-20, 20)];
                
                contentLabel.text = dic[@"content"];
                contentLabel.textColor = [UIColor blackColor];
                contentLabel.numberOfLines = 3;
                contentLabel.font = [UIFont systemFontOfSize:15];
                [contentLabel sizeToFit];
                [view addSubview:contentLabel];
                
                NSString * replyStr = dic[@"reply"];
                if (replyStr.length>0||replyStr!=nil) {
                    
                    UILabel * replyLabel =[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(contentLabel.frame)+10, CGRectGetWidth(view.frame)-20, 20)];

                    replyLabel.textColor = [UIColor grayColor];
                     replyLabel.attributedText = [SHJudgeTools changeColor:[NSString stringWithFormat:@"【回复】: %@",dic[@"reply"]] partStr:@"【回复】:" color:RGB(0x4990aa) font:14];
                    
                    replyLabel.numberOfLines = 4;
                    replyLabel.font = [UIFont systemFontOfSize:14];
                    [replyLabel sizeToFit];
                    [view addSubview:replyLabel];
                    
                    view.frame = CGRectMake(10, 5, self.view.frame.size.width - 20, CGRectGetMaxY(replyLabel.frame) + 20);
                }else {
                    
                    view.frame = CGRectMake(10, 5, self.view.frame.size.width - 20, CGRectGetMaxY(contentLabel.frame) + 20);
                }
            }
            return cell;
        }
    }
}

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section {
    
    float  heardHeight = 350;
    return  heardHeight;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    if ([_typeStr isEqualToString:@"1"]) {
        
        return 10;
    }else {
        
        return 40;
        
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([_typeStr isEqualToString:@"1"]) {
        
        return _webView.frame.size.height;
        
    }else {
       
        NSDictionary * dic = commentArray[indexPath.row];
        
        NSString * replyStr = dic[@"reply"];
        
        if (replyStr.length>0||replyStr!=nil) {
            
            UILabel *contentLabel;
            
            contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(20,60 , WIDTH -40, 20)];
            contentLabel.text = dic[@"content"];
            contentLabel.textColor = Color(67,40,26);
            contentLabel.numberOfLines = 3;
            contentLabel.font = [UIFont systemFontOfSize:15];
            [contentLabel sizeToFit];

            UILabel * replyLabel =[[UILabel alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(contentLabel.frame)+10,WIDTH -40, 20)];
            replyLabel.text = [NSString stringWithFormat:@"【回复】:%@",dic[@"reply"]];
            replyLabel.textColor = [UIColor blackColor];
            replyLabel.numberOfLines = 4;
            replyLabel.font = [UIFont systemFontOfSize:15];
            [replyLabel sizeToFit];
           
            return CGRectGetMaxY(replyLabel.frame)+20;
      
        }else {
        
            UILabel *contentLabel;
            
            contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(20,60 , WIDTH -40, 20)];
            
            contentLabel.text = dic[@"content"];
            contentLabel.textColor = Color(67,40,26);
            contentLabel.numberOfLines = 3;
            contentLabel.font = [UIFont systemFontOfSize:15];
            [contentLabel sizeToFit];

          return CGRectGetMaxY(contentLabel.frame)+20;
        }
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    if ([_typeStr isEqualToString:@"1"]) {
        
        return nil;
    }else {
        
        UIView * footerView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 40)];
        footerView.backgroundColor =[UIColor clearColor];
        UIButton * MoreBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        MoreBtn.frame = CGRectMake(40, 10, WIDTH -80, 20);
        [MoreBtn setTitle:@"点击查看更多" forState:UIControlStateNormal];
        [MoreBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        MoreBtn.titleLabel.font =[UIFont systemFontOfSize:13];
        [MoreBtn addTarget:self action:@selector(moreBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [footerView addSubview:MoreBtn];
        
        if (commentArray.count>=10) {
            MoreBtn.hidden =NO;
        }else {
            MoreBtn.hidden = YES;
        }
        return footerView;
    }
}

-(void) moreBtnClick:(UIButton *)btn {
    
    SHGoodsCommentListController *all =[[SHGoodsCommentListController alloc]init];
    
     all.product_id = self.goodsId;
    
    [self.navigationController pushViewController:all animated:YES];
    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    float  heardHeight = 355;
    
    UIView * heardBgView =[[UIView alloc]initWithFrame:CGRectMake(0,0, WIDTH, heardHeight)];
    
    UIView * heardV =[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 285)];
    heardV.backgroundColor =[UIColor whiteColor];
    [heardBgView addSubview:heardV];
    
//    if (dataDic.count!=0) {
    
        
        NSArray * urlArray;
        if ([dataDic[@"img_srcs"] isKindOfClass:[NSArray class]]) {
            
            urlArray = dataDic[@"img_srcs"];
        }
    
        SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0,0, WIDTH, 200) delegate:self placeholderImage:ImageName(@"img_banner_default")];
        cycleScrollView.backgroundColor =Color(229, 229, 229);
        cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        cycleScrollView.currentPageDotColor = NavBackColor;
        [heardV addSubview:cycleScrollView];
        cycleScrollView.imageURLStringsGroup = urlArray;
        cycleScrollView.clickItemOperationBlock = ^(NSInteger index) {
            
        };
       UILabel * nameLabel;
    
    
    UIView * severView = [[UIView alloc]initWithFrame:CGRectMake(WIDTH - 60, 205, 50, 40)];
    severView.backgroundColor = [UIColor whiteColor];
    [severView tapAction:^{
        
        SeeServiceViewController * see =[[SeeServiceViewController alloc]init];
        [self.navigationController pushViewController:see animated:YES];
    }];
    UIImageView * severImage =[[UIImageView alloc]initWithFrame:CGRectMake(25/2, 0, 25, 25)];
    severImage.image = ImageName(@"icon_detail_cs");
    [severView addSubview:severImage];
    
    UILabel * label =[[UILabel alloc]initWithFrame:CGRectMake(0, 25, 50, 15)];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = RGB(0x666666);
    label.text = @"售后";
    label.font = [UIFont systemFontOfSize:12];
    [severView addSubview:label];
    
    [heardV addSubview:severView];
    
    if (dataDic) {
//
       nameLabel =  [self creatAllLabelFrame:CGRectMake(10, 200 +5, WIDTH-70, 17) andText: dataDic[@"goods_name"] andTextMent:NSTextAlignmentLeft andFountFrame:15 andBgColor:[UIColor clearColor] andTextColor:[UIColor blackColor] onView:heardV];
        nameLabel.numberOfLines = 2;
        [nameLabel sizeToFit];

        price = [self creatTypeLabelFrame:CGRectMake(12, 200+43, WIDTH-30, 20) andText:[NSString stringWithFormat:@"规格：%@",dataDic[@"norm"]] andTextMent:NSTextAlignmentLeft andFountFrame:14 andBgColor:[UIColor clearColor] andTextColor:[UIColor grayColor] onView:heardV];
    
       UILabel * normsLabel =  [self creatAllLabelFrame:CGRectMake(12, 200 + 63, WIDTH/2, 20) andText:[NSString stringWithFormat:@"每件计量：%@",dataDic[@"per"]] andTextMent:NSTextAlignmentLeft andFountFrame:14 andBgColor:[UIColor clearColor] andTextColor:[UIColor grayColor]onView:heardV];
    
       UILabel * emsLabel =  [self creatAllLabelFrame:CGRectMake(WIDTH/2, 200 +63, WIDTH /2-12, 20) andText:[NSString stringWithFormat:@"重量：%@  ",dataDic[@"weight"]] andTextMent:NSTextAlignmentRight andFountFrame:14 andBgColor:[UIColor clearColor] andTextColor:[UIColor grayColor] onView:heardV];
        }
        
        
        UIView * classBtnView =[[UIView alloc]initWithFrame:CGRectMake(0, 295, WIDTH, 45)];
        classBtnView.backgroundColor =[UIColor whiteColor];
        
        [heardBgView addSubview:classBtnView];
        
        UIButton *  detailsBtn =[UIButton buttonWithType:UIButtonTypeSystem];
        detailsBtn.frame = CGRectMake(0, 0, WIDTH/2-1, 43);
        [detailsBtn setTitle:@"图文详情" forState:UIControlStateNormal];
    
    UIView * green_one =[[UIView alloc]initWithFrame:CGRectMake(20, 43, WIDTH/2 -40, 2)];
    green_one.backgroundColor = NavBackColor;
    green_one.hidden = YES;
    [classBtnView addSubview:green_one];
    
    UIView * green_two =[[UIView alloc]initWithFrame:CGRectMake(WIDTH/2 +30, 43, WIDTH/2 -60, 2)];
    green_two.backgroundColor = NavBackColor;
    green_two.hidden = YES;
    [classBtnView addSubview:green_two];
    
        detailsBtn.titleLabel.font =[UIFont systemFontOfSize:15];
        [detailsBtn addTarget:self action:@selector(detailsBtn:) forControlEvents:UIControlEventTouchUpInside];
        [classBtnView addSubview:detailsBtn];
        
        UIButton *  commentBtn =[UIButton buttonWithType:UIButtonTypeSystem];
        commentBtn.frame = CGRectMake(WIDTH/2, 0, WIDTH/2,43);
        [commentBtn setTitle:@"用户评论" forState:UIControlStateNormal];
        if ([_typeStr isEqualToString:@"1"]) {
            green_one.hidden = NO;
            [detailsBtn setTitleColor:NavBackColor forState:UIControlStateNormal];
            [commentBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            green_two.hidden = YES;;
        }else {
            green_one.hidden = YES;
            green_two.hidden = NO;
            [detailsBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [commentBtn setTitleColor:NavBackColor forState:UIControlStateNormal];
        }
        
        commentBtn.titleLabel.font =[UIFont systemFontOfSize:15];
        [commentBtn addTarget:self action:@selector(commentBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [classBtnView addSubview:commentBtn];
    
    UIView * lineView =[[UIView alloc]initWithFrame:CGRectMake(WIDTH/2-1, 10, 0.5, 25)];
    lineView.backgroundColor =[UIColor grayColor];
    [classBtnView addSubview:lineView];
    
    
//    }
    return heardBgView;
}


#pragma mark - 按钮点击事件

-(void)detailsBtn:(UIButton *)btn {
    
    _typeStr = @"1";
    
    [_tableView reloadData];
}

-(void)commentBtnClick:(UIButton *)btn {
    
    _typeStr =@"2";
    
    [_tableView reloadData];
}

// 底部按钮UI
-(void)creatDownView {
    
    UIView * downView =[[UIView alloc]initWithFrame:CGRectMake(0, HEIGHT-48, WIDTH, 48)];
    
    downView.backgroundColor = [UIColor whiteColor];
    
    
    UIView * oneView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH/3, 48)];
    [oneView tapAction:^{
        
        if (verifTokenAndEnter) {
            
            LinkSellerViewController * link =[[LinkSellerViewController alloc]init];
            [self.navigationController pushViewController:link animated:YES];
        }else {
            
            LogingViewController * loging = [[LogingViewController alloc]init];
            [self.navigationController pushViewController:loging animated:YES];
            
        }

       
    }];
    
    UIImageView * callSeller =[[UIImageView alloc]initWithFrame:CGRectMake((WIDTH/3-30)/2, 2, 30, 30)];
    callSeller.image = ImageName(@"icon_detail_contact");
    [oneView addSubview:callSeller];
    
    UILabel * sellLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 33, WIDTH/3, 14)];
    sellLabel.textAlignment = NSTextAlignmentCenter;
    sellLabel.font = [UIFont systemFontOfSize:12];
    sellLabel.textColor = RGB(0x666666);
    sellLabel.text = @"联系卖家";
    [oneView addSubview:sellLabel];
    
    [downView addSubview:oneView];
    
    
    UIView * twoView = [[UIView alloc]initWithFrame:CGRectMake(WIDTH/3, 0, WIDTH/3, 48)];
    [twoView tapAction:^{
        
        
        if (verifTokenAndEnter) {
            
           [self commentBtnClick];
        }else {
            
            LogingViewController * loging = [[LogingViewController alloc]init];
            [self.navigationController pushViewController:loging animated:YES];
            
        }

       
    }];
    UIImageView * myComment =[[UIImageView alloc]initWithFrame:CGRectMake((WIDTH/3-30)/2, 2, 30, 30)];
    myComment.image = ImageName(@"icon_detail_comment");
    [twoView addSubview:myComment];
    
    UILabel * commentLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 33, WIDTH/3, 14)];
    commentLabel.textAlignment = NSTextAlignmentCenter;
    commentLabel.font = [UIFont systemFontOfSize:12];
    commentLabel.textColor = RGB(0x666666);
    commentLabel.text = @"我要评论";
    [twoView addSubview:commentLabel];
    
    [downView addSubview:twoView];
    
    
    UIImageView * addCarImage = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH/3*2, 0,WIDTH/3, 48)];
    [addCarImage tapAction:^{
        
        if (verifTokenAndEnter) {
            
             [self addShopCarGoods];
        }else {
        
            LogingViewController * loging = [[LogingViewController alloc]init];
           [self.navigationController pushViewController:loging animated:YES];
        
        }
       
        
        NSLog(@"加入购物车");
    }];
    addCarImage.image = ImageName(@"img_home_nav_bg");
//    addCarImage.userInteractionEnabled = YES;
     [downView addSubview:addCarImage];
    
    
    
    UIImageView * carImage =[[UIImageView alloc]initWithFrame:CGRectMake((WIDTH/3-30)/2, 2, 30, 30)];
    carImage.image = ImageName(@"icon_puductor_shoppingcart");
    [addCarImage addSubview:carImage];
    
    UILabel * carLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 33, WIDTH/3, 14)];
    carLabel.textAlignment = NSTextAlignmentCenter;
    carLabel.font = [UIFont systemFontOfSize:12];
    carLabel.textColor = [UIColor whiteColor];
    carLabel.text = @"加入购物车";
    [addCarImage addSubview:carLabel];
    
//    UIButton * addCar =[UIButton buttonWithType:UIButtonTypeCustom];
//    addCar.frame  = CGRectMake(0, 0,WIDTH/3, 48);
//    [addCar addTarget:self action:@selector(shopCarBtnClick) forControlEvents:UIControlEventTouchUpInside];
//    [addCarImage addSubview:addCar];
    
    [self.view addSubview:downView];
    
}

-(void)shopCarBtnClick {
    
    [self addShopCarGoods];
}



-(UIView *)creatOneViewLabelFrame:(CGRect)cgrect andText:(NSString *)str onView:(UIView *)view {
    
    
    UIView * xxview =[[UIView alloc]initWithFrame:cgrect];
    xxview.backgroundColor =[UIColor whiteColor];
    
    UILabel * messageLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 33, xxview.frame.size.width, 12)];
    messageLabel.text =str;
    messageLabel.textAlignment =NSTextAlignmentCenter;
    messageLabel.font =[UIFont systemFontOfSize:11];
    [xxview addSubview:messageLabel];
    
    [view addSubview:xxview];
    return xxview;
    
    
}
//one 按钮

-(UIButton *)meassgeBtnCreatOneBtnFrame:(CGRect)cgrect andImageName:(NSString *)imageName andAction:(SEL)action onView:(UIView *)view {
    
    UIButton * messageBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    messageBtn.frame = cgrect;
    [messageBtn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [messageBtn setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [view addSubview:messageBtn];
    return messageBtn;
}


//heardLabel
-(UILabel *)creatAllLabelFrame:(CGRect)cgrect andText:(NSString *)str andTextMent:(NSTextAlignment)textAlignment andFountFrame:(CGFloat)font andBgColor:(UIColor *)lor andTextColor:(UIColor *)textColor onView:(UIView *)view {
    
    UILabel * label =[[UILabel alloc]initWithFrame:cgrect];
    label.text =str;
    label.textAlignment =textAlignment;
    label.font = [UIFont systemFontOfSize:font];
    label.backgroundColor =lor;
    label.textColor =textColor;
    label.adjustsFontSizeToFitWidth =YES;
    [view addSubview:label];
    
     return label;
    
}

//预处理文字
-(UILabel *)creatTypeLabelFrame:(CGRect)cgrect andText:(NSString *)str andTextMent:(NSTextAlignment)textAlignment andFountFrame:(CGFloat)font andBgColor:(UIColor *)lor andTextColor:(UIColor *)textColor onView:(UIView *)view {
    
    UILabel * label =[[UILabel alloc]initWithFrame:cgrect];
    label.text =str;
    label.textAlignment =textAlignment;
    label.font = [UIFont systemFontOfSize:font];
    label.backgroundColor =lor;
    label.textColor =textColor;
    [view addSubview:label];
    return label;
}

-(void)creatLineView:(CGRect)rec andOnView:(UIView *)view{
    
    UIView * line =[[UIView alloc]initWithFrame:rec];
    line.backgroundColor =[UIColor lightGrayColor];
    [view addSubview:line];
    
}

//加车

-(void)creatShoppingAndCarBtnFrame:(CGRect)cgrect andTitle:(NSString *)title andAction:(SEL)action andColor:(UIColor*)col andTitleColor:(UIColor *)titleCol andBorderColo:(UIColor *)borderCol onView:(UIView *)view {
    
    UIButton * carBtn =[UIButton buttonWithType:UIButtonTypeSystem];
    carBtn.frame =cgrect;
    carBtn.layer.cornerRadius = 5.f;
    carBtn.layer.masksToBounds = YES;
    carBtn.layer.borderWidth =1.f;
    carBtn.layer.borderColor = borderCol.CGColor;
    carBtn.backgroundColor =col;
    
    [carBtn setTitleColor:titleCol forState:UIControlStateNormal];
    carBtn.titleLabel.font =[UIFont systemFontOfSize:15];
    [carBtn setTitle:title forState:UIControlStateNormal];
    [carBtn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:carBtn];
}

//shop
-(void)creatShopBtnFrame:(CGRect)ret andTitle:(NSString *)title andClick:(SEL)click onView:(UIView *)view{
    
    UIButton  * classBtn =[UIButton buttonWithType:UIButtonTypeSystem];
    classBtn.frame = ret;
    classBtn.layer.borderWidth =1.f;
    classBtn.layer.cornerRadius = 4.f;
    classBtn.layer.masksToBounds = YES;
    classBtn.layer.borderColor = [UIColor redColor].CGColor;
    [classBtn setTitle:title forState:UIControlStateNormal];
    classBtn.titleLabel.font =[UIFont systemFontOfSize:14];
    [classBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [classBtn addTarget:self action:click forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:classBtn];
}
//
/**
 *  加车
*/
-(void)addShopCarGoods{
    
    NSDictionary * dic = @{@"user_id":USER_DEFAULTGet(@"user_id"),
                           @"token":USER_DEFAULTGet(@"token"),
                           @"goods_id":self.goodsId};
    
    
    SHuiMBhudTextTimeStr(@"正在添加");
    [PostNetWorking postNetWorkingStr:RequestUrlStr(add_goodsCar_api) andparameters:dic Success:^(id responseObject) {
        SHuiMBHidleYes;
        if (codeSucess) {
            
            SHuiMBhudTextTimeStr(@"添加购物车成功！");
            
        }else {
            
            SHuiMBhudTextTimeStr(@"请稍后再试");
        }
        
    } failed:^(NSError *error) {
        SHuiMBHidleYes;
        SHuiMBhudTextNetError;
    }];


}

/**
 *  商品数据
 */
-(void)getGoodsDataRequest {
    
    NSString * parametersStr = [NSString stringWithFormat:@"%@%@",NetWorkAddress_api,get_goodsDetails_api];
    
    NSDictionary *  dic = @{@"goods_id":self.goodsId,
                            };
    
    [PostNetWorking postNetWorkingStr:parametersStr  andparameters:dic  Success:^(id responseObject) {
        
        if ([responseObject[@"code"] intValue]==200) {
            
            
            dispatch_async(dispatch_get_global_queue(0, 0), ^{
                
                if (responseObject[@"datas"]!=nil) {
                    
                    dataDic = responseObject[@"datas"];
                    
//                    commentArray = dataDic[@"comments"];
                    
                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    
                    [_tableView.mj_header endRefreshing];
                    [self creatWEB];
                    [_tableView reloadData];
                });
                
            });
            
        }else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);

        }
 
    } failed:^(NSError *error) {
        
        SHuiMBhudTextNetError;
    }];
    
}

/**
 *  商品评论
 */
-(void)getGoodsCommentDataRequest {
    
    NSString * parametersStr = [NSString stringWithFormat:@"%@%@",NetWorkAddress_api,get_goodsComment_api];
    
    NSDictionary *  dic = @{@"goods_id":self.goodsId,
                            @"page":@"1",
                            @"page_num":@"10"
                            };
    
    [PostNetWorking postNetWorkingStr:parametersStr  andparameters:dic  Success:^(id responseObject) {
        
        if ([responseObject[@"code"] intValue]==200) {

            dispatch_async(dispatch_get_global_queue(0, 0), ^{
                
                if ([responseObject[@"datas"][@"list"] isKindOfClass:[NSArray class]]) {

                     commentArray = responseObject[@"datas"][@"list"];
                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    
                    [_tableView.mj_header endRefreshing];
//                    [self creatWEB];
                    [_tableView reloadData];
                });
                
            });
            
        }else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
            
        }
        
    } failed:^(NSError *error) {
        
        SHuiMBhudTextNetError;
    }];
    
}





-(void)addReplyCommentRequest{
    
    
    NSDictionary * dic = @{@"user_id":USER_DEFAULTGet(@"user_id"),
                           @"token":USER_DEFAULTGet(@"token"),
                           @"content":self.introTextView.text,
                           @"goods_id":self.goodsId};
    SHuiMBhubNoTimeLoding;
    [PostNetWorking postNetWorkingStr:RequestUrlStr(add_goodsComment_api) andparameters:dic Success:^(id responseObject) {
        SHuiMBHidleYes;
        if (codeSucess) {
            
            SHuiMBhudTextTimeStr(@"提交成功,待审核");
           
            [self getGoodsCommentDataRequest];
        }else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
        SHuiMBHidleYes;
        SHuiMBhudTextNetError;
    }];
    
}



@end
